import request from '@/config/axios'

export interface BookSetCreateReqVO {
  title: string
  cover?: string
  description?: string
  categoryId: number
  ageRange?: string
  source?: string
  difficultyLevel: string
  language: string
  isRecommended?: boolean
  isActive?: boolean
}

export interface BookSetUpdateReqVO extends BookSetCreateReqVO {
  id: number
}

export interface BookSetAdminRespVO {
  id: number
  title: string
  cover?: string
  description?: string
  categoryId: number
  ageRange?: string
  bookCount: number
  source?: string
  difficultyLevel: string
  language: string
  isRecommended: boolean
  isActive: boolean
  createTime: string
  updateTime: string
  creator?: string
  updater?: string
}

export interface BookSetPageReqVO extends PageParam {
  title?: string
  categoryId?: number
  language?: string
  difficultyLevel?: string
  isRecommended?: boolean
  isActive?: boolean
}

// 创建绘本集
export const createBookSet = (data: BookSetCreateReqVO) => {
  return request.post({
    url: '/reading/admin/book-sets/create',
    data
  })
}

// 更新绘本集
export const updateBookSet = (data: BookSetUpdateReqVO) => {
  return request.put({
    url: '/reading/admin/book-sets/update',
    data
  })
}

// 删除绘本集
export const deleteBookSet = (id: number) => {
  return request.delete({
    url: '/reading/admin/book-sets/delete',
    params: { id }
  })
}

// 获取绘本集详情
export const getBookSet = (id: number) => {
  return request.get({
    url: '/reading/admin/book-sets/get',
    params: { id }
  })
}

// 获取绘本集分页
export const getBookSetPage = (params: BookSetPageReqVO) => {
  return request.get({
    url: '/reading/admin/book-sets/page',
    params
  })
}

// 获取下一个绘本集ID
export const getNextBookSetId = () => {
  return request.get({
    url: '/reading/admin/book-sets/next-id'
  })
}

// 更新绘本集的绘本数量
export const updateBookSetBookCount = (bookSetId: number) => {
  return request.put({
    url: `/reading/admin/book-sets/${bookSetId}/update-book-count`
  })
}

// 批量删除绘本集
export const batchDeleteBookSet = (ids: number[]) => {
  return request.delete({
    url: '/reading/admin/book-sets/batch-delete',
    data: { ids }
  })
}

// 批量更新绘本集状态
export const batchUpdateBookSetStatus = (ids: number[], isActive: boolean) => {
  return request.put({
    url: '/reading/admin/book-sets/batch-update-status',
    data: { ids, isActive }
  })
}
